<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>编辑会员</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="{__STATIC__}/layuiAdmin/layui/css/layui.css" rel="stylesheet">
    <link href="{__STATIC__}/layuiAdmin/adminui/dist/css/admin.css" rel="stylesheet">
    <link href="{__STATIC__}/layuiAdmin/style/style.css" rel="stylesheet">
    <style>
        html {background: #fff;padding-top: 20px;}
    </style>
</head>
<body>
    <div class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">用户名：</label>
            <div class="layui-form-mid layui-word-aux">{$data.uid}</div>
            <button type="button" class="layui-btn layui-btn-info layui-btn-xs btn-set" style="margin-top: 8px;" data-type="editPwd">修改密码</button>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">会员等级：</label>
            <div class="layui-input-inline">
                <select name="m_level">
                    <option value="0">普通会员</option>
                    {volist name="levelList" id="vo"}
                    <option value="{$vo.id}" {eq name="$data->getData('level_id')" value="$vo.id"}selected{/eq}>{$vo.title}</option>
                    {/volist}
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">会员昵称：</label>
            <div class="layui-input-inline">
                <input type="text" name="m_nickname" value="{$data.nickname}" placeholder="请输入会员昵称" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">绑定手机：</label>
            <div class="layui-input-inline">
                <input type="text" name="m_tel" value="{$data.mobile}" placeholder="请输入11位手机号" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">11位手机号</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">绑定邮箱：</label>
            <div class="layui-input-inline">
                <input type="text" name="m_email" value="{$data.email}" placeholder="请输入邮箱地址" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">如：888@qq.com</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">会员标签：</label>
            <div class="layui-input-block">
                {volist name="labelList" id="vo"}
                <input type="checkbox" name="label[]" lay-skin="primary" title="{$vo.title}" value="{$vo.id}" {eq name=":in_array($vo.id,explode(',',$data.label_id))" value="1"}checked{/eq} />
                {/volist}
            </div>
        </div>
        {neq name="$data.other_user" value=""}
        <div class="layui-form-item">
            <label class="layui-form-label">第三方登录：</label>
            <div class="layui-form-mid layui-word-aux">{$data.other_user}</div>
        </div>
        {/neq}
        <div class="layui-form-item">
            <label class="layui-form-label">会员积分：</label>
            <div class="layui-form-mid layui-word-aux">{$data.integral}</div>
            <button type="button" class="layui-btn layui-btn-info layui-btn-xs btn-set" style="margin-top: 8px;" data-type="editIntegral">调整积分</button>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">会员余额：</label>
            <div class="layui-form-mid layui-word-aux">{$data.balance}</div>
            <button type="button" class="layui-btn layui-btn-info layui-btn-xs btn-set" style="margin-top: 8px;" data-type="editBalance">调整余额</button>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">会员成长值：</label>
            <div class="layui-form-mid layui-word-aux">{$data.growth}</div>
            <button type="button" class="layui-btn layui-btn-info layui-btn-xs btn-set" style="margin-top: 8px;" data-type="editGrowth">调整成长值</button>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否激活：</label>
            <div class="layui-input-inline w50">
                <input type="checkbox" name="m_work" value="1" lay-text="是|否" {eq name="$data.is_work" value="1"}checked{/eq} lay-skin="switch">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">开启分销：</label>
            <div class="layui-input-inline w50">
                <input type="checkbox" name="m_fx" value="1" lay-text="是|否" {eq name="$data.is_fx" value="1"}checked{/eq} lay-skin="switch">
            </div>
        </div>
        <input type="hidden" name="m_id" id="m_id" value="{$data.id}">
        <input type="hidden" name="m_uid" value="{$data.uid}">
        <input type="hidden" name="m_pwd" value="{:empty($data.pwd) ? 0 : $data.pwd}">
        <div class="layui-form-item layui-hide">
            <input type="button" lay-submit lay-filter="LAY-submit" id="LAY-submit" value="确认">
        </div>
    </div>
</body>
</html>
<script src="{__STATIC__}/layuiAdmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '{__STATIC__}/layuiAdmin/' // 静态资源所在路径
    }).use(['index', 'layer'], function(){
        let $ = layui.$;
        let layer = layui.layer;
        let m_id = $('#m_id').val();

        //操作按钮
        $('.btn-set').on('click', function(){
            let type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        let active = {
            //调整积分
            editIntegral : function(){
                layer.open({
                    type: 2
                    ,title: '调整积分'
                    ,content: "{:url('editIntegral')}?uid=" + m_id
                    ,maxmin: false
                    ,area: ['500px', '280px']
                    ,btn: ['确定', '取消']
                    ,yes: function(index, layero){
                        let iframeWindow = window['layui-layer-iframe'+ index];
                        let submitID = 'LAY-submit';
                        let submit = layero.find('iframe').contents().find('#'+ submitID);

                        //监听提交
                        iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
                            let field = data.field; //获取提交的字段
                            $.ajax({
                                type:"post",
                                url:"{:url('saveIntegral')}",
                                data: {
                                    m_fee:field.m_fee,
                                    m_info:field.m_info,
                                    m_uid:field.m_uid
                                },
                                dataType:"json",
                                beforeSend: function () {
                                    layer.load(1);
                                },
                                success:function(res){
                                    layer.close(layer.index);
                                    if(res.code == 0){
                                        location.reload();
                                    }
                                    else {
                                        layer.msg(res.msg);
                                    }
                                }
                            });
                        });
                        submit.trigger('click');
                    }
                });
            },
            //调整余额
            editBalance : function(){
                layer.open({
                    type: 2
                    ,title: '调整余额'
                    ,content: "{:url('editBalance')}?uid=" + m_id
                    ,maxmin: false
                    ,area: ['500px', '280px']
                    ,btn: ['确定', '取消']
                    ,yes: function(index, layero){
                        let iframeWindow = window['layui-layer-iframe'+ index];
                        let submitID = 'LAY-submit';
                        let submit = layero.find('iframe').contents().find('#'+ submitID);

                        //监听提交
                        iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
                            let field = data.field; //获取提交的字段
                            $.ajax({
                                type:"post",
                                url:"{:url('saveBalance')}",
                                data: {
                                    m_fee:field.m_fee,
                                    m_info:field.m_info,
                                    m_uid:field.m_uid
                                },
                                dataType:"json",
                                beforeSend: function () {
                                    layer.load(1);
                                },
                                success:function(res){
                                    layer.close(layer.index);
                                    if(res.code == 0){
                                        location.reload();
                                    }
                                    else {
                                        layer.msg(res.msg);
                                    }
                                }
                            });
                        });
                        submit.trigger('click');
                    }
                });
            },
            //调整成长值
            editGrowth : function(){
                layer.open({
                    type: 2
                    ,title: '调整成长值'
                    ,content: "{:url('editGrowth')}?uid=" + m_id
                    ,maxmin: false
                    ,area: ['500px', '280px']
                    ,btn: ['确定', '取消']
                    ,yes: function(index, layero){
                        let iframeWindow = window['layui-layer-iframe'+ index];
                        let submitID = 'LAY-submit';
                        let submit = layero.find('iframe').contents().find('#'+ submitID);

                        //监听提交
                        iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
                            let field = data.field; //获取提交的字段
                            $.ajax({
                                type:"post",
                                url:"{:url('saveGrowth')}",
                                data: {
                                    m_fee:field.m_fee,
                                    m_info:field.m_info,
                                    m_uid:field.m_uid
                                },
                                dataType:"json",
                                beforeSend: function () {
                                    layer.load(1);
                                },
                                success:function(res){
                                    layer.close(layer.index);
                                    if(res.code == 0){
                                        location.reload();
                                    }
                                    else {
                                        layer.msg(res.msg);
                                    }
                                }
                            });
                        });
                        submit.trigger('click');
                    }
                });
            },
            //修改密码
            editPwd : function(){
                layer.open({
                    type: 2
                    ,title: '修改密码'
                    ,content: "{:url('editPwd')}?uid=" + m_id
                    ,maxmin: false
                    ,area: ['500px', '280px']
                    ,btn: ['确定', '取消']
                    ,yes: function(index, layero){
                        let iframeWindow = window['layui-layer-iframe'+ index];
                        let submitID = 'LAY-submit';
                        let submit = layero.find('iframe').contents().find('#'+ submitID);

                        //监听提交
                        iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
                            var field = data.field; //获取提交的字段
                            $.ajax({
                                type:"post",
                                url:"{:url('savePwd')}",
                                data: {
                                    password:field.password,
                                    password_confirm:field.password_confirm,
                                    m_uid:field.m_uid
                                },
                                dataType:"json",
                                beforeSend: function () {
                                    layer.load(1);
                                },
                                success:function(res){
                                    layer.close(layer.index);
                                    if(res.code == 0){
                                        location.reload();
                                    }
                                    else {
                                        layer.msg(res.msg);
                                    }
                                }
                            });
                        });
                        submit.trigger('click');
                    }
                });
            },

        };

    });
</script>